<?php

/**
 * 
 * 
 *
 */
class Quad_Observable_Event extends Quad_MagicProperties {

	public $target;
	protected $_isStoppable = false;
	protected $_isStopped = false;
	protected $_isPreventable = false;
	
	public function __construct(Quad_Observable $target, $addlData, $isStoppable, $isPreventable) {
		$this->setProperties($addlData);
		$this->target = $target;
		$this->_isPreventable = $isPreventable;
	}
	
	public function stop() {
		$this->preventPropagation();
		$this->preventDefault();
		return $this;
	}
	
	public function preventDefault() {
		if ($this->_isPreventable) {
			throw new Quad_Observable_Event_Exception();
		}
		return $this;
	}
	
	public function preventPropagation() {
		if ($this->_isStoppable) {
			$this->_isStopped = true;
		}		
	}
	
	public function willPropagate() {
		return $this->_isStopped;
	}
	
	public function __call($m,$a) {
		throw new Quad_Exception("Call to undefined function '$m'.");
	}
  
}